package com.newlink.building.userinfo.mvp

import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.model.bean.*
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_AuthPasswordContract
import com.newlink.building.userinfo.mvp.model.Module_UserInfo_AuthPasswordModel

/**
 * @author wangyang
 * @date 2022/9/20
 * @description 我的-关于页面的Presenter
 */
class Module_UserInfo_AuthPasswordPresenter :
    BasePresenter<Module_UserInfo_AuthPasswordContract.Model, Module_UserInfo_AuthPasswordContract.View>(),
    Module_UserInfo_AuthPasswordContract.Presenter {

    override fun createModel(): Module_UserInfo_AuthPasswordContract.Model? = Module_UserInfo_AuthPasswordModel()

    override fun updateOpenDoorPassword(token: String, uId: String, password: String) {
        mView?.showLoading()
        mModel?.updateOpenDoorPassword(token, uId, password)?.ss(mModel, mView) {
            mView?.hideLoading()
            mView?.onAuthConfirmResponse(it)
        }
    }

    override fun loadCurrentPassword(token: String, uId: String) {
        val data = LoadAuthDataRequestBody(keyType = 2)
        mModel?.getCardList(LoadFaceListDataRequest(accessToken = token, uId = uId, data = data))
            ?.ss(mModel, mView) { result ->
                val total = result?.data?.total
                if (total != null) {
                    if (total > 0) {
                        val pwdResult = result?.data?.list?.get(total - 1)
                        mView?.getPasswordSuccess(pwdResult)
                    }
                }

                mView?.getPasswordFailed("")
            }
    }

//    override fun onAuthConfirmResponse(
//        id: Int,
//        result: BaseBean?
//    ) {
//        mView?.hideLoading()
//        mView?.onAuthConfirmResponse(id, result)
//    }
//
//    override fun onAuthListResponse(
//        id: Int, result: KcpResult<FaceListData>?
//    ) {
//        android.util.Log.d("jake", "auth pwd total >>> ${result?.data?.total}")
//
//        val total = result?.data?.total
//        if (total != null) {
//            if (total > 0) {
//                val pwdResult = result?.data?.list?.get(total-1)
//                mView?.getPasswordSuccess(pwdResult)
//                return
//            }
//        }
//
//        mView?.getPasswordFailed("")
//    }

}